home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / VEFE23~1.CLS < prev    next >
Text File  |  1997-06-14  |  2KB  |  85 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CVectorSngWalker"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. ' Implement Basic-friendly version of IEnumVARIANT
  13. Implements IVariantWalker
  14. ' Delegate to class that implements real IEnumVARIANT
  15. Private vars As CEnumVariant
  16. ' Connect back to parent collection
  17. Private connect As CVectorSng
  18.  
  19. Public Enum EErrorVectorSngWalker
  20.     eeBaseVectorSngWalker = 13370   ' CVectorSngWalker
  21. End Enum
  22.  
  23. ' Private state data
  24. Private iCur As Long
  25.  
  26. Private Sub Class_Initialize()
  27.     ' Initialize position in collection
  28.     iCur = 0
  29.     ' Connect walker to CEnumVariant so it can call methods
  30.     Set vars = New CEnumVariant
  31.     vars.Attach Me
  32. End Sub
  33.  
  34. ' Receive connection from CVectorSng
  35. Sub Attach(connectA As CVectorSng)
  36.     Set connect = connectA
  37. End Sub
  38.  
  39. ' Return IEnumVARIANT (indirectly) to client collection
  40. Function NewEnum() As stdole.IEnumVARIANT
  41.     Set NewEnum = vars
  42. End Function
  43.  
  44. ' Implement IVariantWalker methods
  45. Private Function IVariantWalker_More(v As Variant) As Boolean
  46.     ' Move to next element
  47.     iCur = iCur + 1
  48.     ' Return False if no more data
  49.     If iCur > connect.Last Then Exit Function
  50.     ' Return element through reference
  51.     v = connect.Vector(iCur)
  52.     IVariantWalker_More = True
  53. End Function
  54.  
  55. Private Sub IVariantWalker_Reset()
  56.     ' Move to first element
  57.     iCur = 0
  58. End Sub
  59.  
  60. Private Sub IVariantWalker_Skip(c As Long)
  61.     ' Skip a given number of elements
  62.     iCur = iCur + c
  63. End Sub
  64.  
  65. #If fComponent = 0 Then
  66. Private Sub ErrRaise(e As Long)
  67.     Dim sText As String, sSource As String
  68.     If e > 1000 Then
  69.         sSource = App.ExeName & ".VectorSngWalker"
  70.         Select Case e
  71.         Case eeBaseVectorSngWalker
  72.             BugAssert True
  73.        ' Case ee...
  74.        '     Add additional errors
  75.         End Select
  76.         Err.Raise COMError(e), sSource, sText
  77.     Else
  78.         ' Raise standard Visual Basic error
  79.         sSource = App.ExeName & ".VBError"
  80.         Err.Raise e, sSource
  81.     End If
  82. End Sub
  83. #End If
  84.  
  85.